package com.jin.webvideo.config.filter.access.handler;

import com.jin.webvideo.config.filter.access.AccessControl;
import com.jin.webvideo.config.filter.access.GlobalStore;
import com.jin.webvideo.entity.SessionStore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * handler 链式处理
 */
public class ListHandlerChain implements HandlerChain {
    private List<AccessHandler> handlers;
    public ListHandlerChain(List<AccessHandler> handlers) {
        this.handlers = handlers;
    }
    private int idx;
    @Override
    public boolean doHandle(AccessControl.Access access, GlobalStore globalStore, HttpServletRequest request, SessionStore store) {
        if (idx >= handlers.size()) {
            return false;
        }
        return handlers.get(idx++).handle(globalStore, store, request, access, this);
    }
}
